<!--
 * @Description:
 * @Author: wyh19
 * @Date: 2021-07-21
-->
<template>
  <el-form ref="form" :model="formData" :disabled="formDisabled" :rules="rules" label-width="80px"
           size="small" @validate="handleValidate">
    <el-button type="primary" size="small" @click="handleAdd">增加</el-button>
    <div v-for="(item,index) in formData.workList" :key="index">
      <el-button size="mini" @click="handleRemove(index)">删除</el-button>
      <el-form-item label="公司" :prop="`workList.${index}.company`" :rules="rules.company"
                    class="field-wrapper">
        <el-input v-model="item.company" />
      </el-form-item>
      <el-form-item label="司龄" class="field-wrapper">
        <el-input-number v-model="item.month" />
        <span>(个月)</span>
      </el-form-item>
      <el-form-item label="离职原因" :prop="`workList.${index}.reason`"
                    :rules="item.month <10 ?rules.reason:{}" class="field-wrapper">
        <el-input v-model="item.reason" />
      </el-form-item>
    </div>
  </el-form>
</template>

<script>
import SuperFormMixin from '@/mixins/super-form-mixin'
export default {
  name: 'Form3',
  mixins: [SuperFormMixin],
  data() {
    return {
      rules: {
        company: [
          { required: true, message: '请输入公司名称', trigger: ['change', 'blur'] }
        ],
        reason: [
          { required: true, message: '请输入离职原因', trigger: ['change', 'blur'] }
        ]
      }
    }
  },
  methods: {
    handleAdd() {
      this.formData.workList.push({})
    },
    handleRemove(i) {
      this.formData.workList.splice(i, 1)
    }
  }
}
</script>

<style scoped lang="scss">
.field-wrapper {
  width: 320px;
}
</style>
